package utgame.com.fakelegendary.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import utgame.com.fakelegendary.R;

/**
 * Created by xueal on 2018/1/16.
 */

public class Friend {

    private int imageId;          //使用id锁定好友图片
    private String imageName;     //对应的好友名字
    private boolean isNewMessage;
    private boolean isOnline;

    private ArrayList<Msg> mChatList = new ArrayList<>();           // 别人和我的聊天记录


    public static final int[] imageIds = { R.drawable.hero
    };

    public Friend(int imageId, String imageName) {
        super();
        this.imageId = imageId;
        this.imageName = imageName;
    }

    public Friend(int imageId, String imageName, boolean isOnline) {
        super();
        this.imageId = imageId;
        this.imageName = imageName;
        this.isOnline = isOnline;
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }

    public boolean getOnline() {
        return isOnline;
    }

    public void setOnline(boolean online) {
        isOnline = online;
    }

    public boolean getNewMessage() {
        return isNewMessage;
    }

    public void setNewMessage(boolean newMessage) {
        isNewMessage = newMessage;
    }

//    //    如果该对象小于、等于或大于指定对象，则分别返回负整数、零或正整数
//    @Override
//    public int compareTo(@NonNull Friend o) {
//        if (this.getOnline() && !o.getOnline()) //这里比较的是什么 sort方法实现的就是按照此比较的东西从小到大排列
//            return -1;
//        else if (!this.getOnline() && o.getOnline())
//            return 1;
//        else
//            return 0;
//    }

    public static int check(boolean tag){ return tag ? 1:0; }

    public void addChat(Msg msg){
        mChatList.add(new Msg(msg.getContent(), msg.getType()));
    }
    public ArrayList<Msg> getChatList(){
        return mChatList;
    }

    public long getLastChatTime(){
        if (!mChatList.isEmpty()){
            return mChatList.get(mChatList.size() - 1).getTime();
        }
        return 0;
    }

    public static void removeNotChatFriend(List<Friend> friendList){
        Iterator<Friend> iterator = friendList.iterator();
        while(iterator.hasNext()) {
            Friend friend = iterator.next();
            if(friend.getLastChatTime() <= 0) {
                iterator.remove();
            }
        }
    }

}
